package co2.bean;

import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import co2.engine.DAOInterface;
import co2.pojos.Material;
import co2.pojos.PR;

@ManagedBean
@ViewScoped
public class FrontPrBean extends AbstractBean implements Serializable {
	private static final long serialVersionUID = 1L;
	
	private List<PR> list;
	private boolean stdet = false;
	
	@Autowired
	@Qualifier("daoI")
	private DAOInterface dao;
	
	private PR pr;
	
	@PostConstruct
	public void postCon(){
		 
			Map map = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
			pr = (PR) map.get("prFront");
			if(pr==null){
				list = dao.getAllPR();
				stdet = false;
			}else{
				stdet = true;
				map.remove("prFront");
			}
		 
		
	}
	

	public void detail(){
		Map map = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
		
		map.put("prFront", pr);
		try{
			String requestPath = FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath() ;
			
			
				FacesContext.getCurrentInstance().getExternalContext().redirect(requestPath+"/jsf/target/user_pr.jsf");
		
			
		}catch(Exception e){
			e.printStackTrace();
			FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,"redirect error",""));
		}
		
		
	}


	public List<PR> getList() {
		return list;
	}


	public void setList(List<PR> list) {
		this.list = list;
	}


	public DAOInterface getDao() {
		return dao;
	}


	public void setDao(DAOInterface dao) {
		this.dao = dao;
	}


	public PR getPr() {
		return pr;
	}


	public void setPr(PR pr) {
		this.pr = pr;
	}


	public boolean isStdet() {
		return stdet;
	}


	public void setStdet(boolean stdet) {
		this.stdet = stdet;
	}
	
	
}
